package com.lb.web;

import com.lb.handler.OnlineWebSocketServer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @version 1.0
 * @Author: Edward
 * @Date: 2021/5/26 9:15
 * @Description:
 */
@RestController
public class MsgController {
    @Resource
    private OnlineWebSocketServer webSocketServer;

    @RequestMapping("/sendTo")
    public String sendTo(@RequestParam("userId") String userId, @RequestParam("msg") String msg) throws IOException {
        webSocketServer.sendMessageTo(msg, userId);
        return "推送成功";
    }

    @RequestMapping("/sendAll")
    public String sendAll(@RequestParam("msg") String msg) throws IOException {
        webSocketServer.sendMessageAll(msg);
        return "推送成功";
    }
}
